<?php

namespace App\Models\Common;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;

class FsCompanyRoleMappingModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'fs_company_role_mappings';

    protected $fillable = [
        'fsCompanyUserMappingId', // 复核人，这个id=0
        'fsCompanyId',
        'rmsUserId',
        'roleId',
    ];

    protected $appends = [
        'roleText',
    ];

    const ROLE_ID_COMPANY_FIRST = 1; // 供应商初审
    const ROLE_ID_KF_REVIEWER   = 2; // 总部复审

    const ROLE_TEXT = [
        self::ROLE_ID_COMPANY_FIRST => '初审',
        self::ROLE_ID_KF_REVIEWER   => '复审',
    ];

    public function getRoleTextAttribute(): string
    {
        return self::ROLE_TEXT[$this->roleId] ?? '';
    }

    /**
     * 获取供应商下的管理人员ids
     * @param int $fsCompanyId
     * @return array
     */
    public static function getCompanyUserIdsByRole(int $fsCompanyId, int $roleId): array
    {
        return self::query()
                   ->where('fsCompanyId', $fsCompanyId)
                   ->where('roleId', $roleId)
                   ->pluck('rmsUserId')
                   ->toArray();
    }
}
